package com.bootdo.acitvity.test;

import org.apache.ibatis.javassist.ClassPool;
import org.apache.ibatis.javassist.CtClass;
import org.apache.ibatis.javassist.CtMethod;
import org.apache.ibatis.javassist.CtNewMethod;

public class MyGenerator {

    public static void main(String[] args) throws Exception {
        ClassPool classPool = ClassPool.getDefault();
        CtClass ctClass = classPool.makeClass("com.bootdo.acitvity.test.Program");
        CtMethod method = CtNewMethod.make("public void code(){}", ctClass);
        // 插入方法代码
        method.insertBefore("System.out.println(\"I'm a Programmer,Just Coding.....\");");
        ctClass.addMethod(method);
        // 保存生成的字节码
        ctClass.writeFile("d://temp");
    }
}
